<?php
namespace tp5_lib\connect\controller;
use connect\base\HttpsHtmlConnect;
use connect\base\HttpsJsonConnect;
use connect\base\HttpsQueryConnect;

/**
 * 基础功能测试
 */
class BaseTest
{
    protected $host;//接口地址
    protected $params;//URL中的参数
    protected $data;//测试发送的数据
    function __construct(){
        if(isset($_GET["api"])&&$_GET["api"]==="cb"){
            $this->host="http://127.0.0.1/thinkphp/public/connect/Callback";
        }
        else{
            $this->host="http://127.0.0.1/thinkphp/public/connect/PlainApi";
        }
        $this->params=[
            "action"=>"test"
        ];
        $this->data=[
            "message"=>"hello world !"
        ];
    }
    public function index()
    {
        $this->host="http://127.0.0.1/thinkphp/public/connect/PlainApi";
        $this->htmlGet();
        $this->htmlPost();
        $this->jsonGet();
        $this->jsonPost();
        $this->queryGet();
        $this->queryPost();
        $this->host="http://127.0.0.1/thinkphp/public/connect/Callback";
        $this->jsonGet();
        $this->jsonPost();
        $this->queryGet();
        $this->queryPost();
    }
    public function htmlGet()
    {
        $connect=new HttpsHtmlConnect;
        $response=$connect->get($this->host."/html?cd=21321",$this->params);
        echo $response;
    }
    public function htmlPost()
    {
        $connect=new HttpsHtmlConnect;
        $response=$connect->post($this->host."/html",$this->data,$this->params);
        echo $response;
    }
    public function jsonGet()
    {
        $connect=new HttpsJsonConnect;
        $response=$connect->get($this->host."/json",$this->params);
        var_dump($response);
    }
    public function jsonPost()
    {
        $connect=new HttpsJsonConnect;
        $response=$connect->post($this->host."/json",$this->data,$this->params);
        var_dump($response);
    }
    public function queryGet()
    {
        $connect=new HttpsQueryConnect;
        $response=$connect->get($this->host."/query",$this->params);
        var_dump($response);
    }
    public function queryPost()
    {
        $connect=new HttpsQueryConnect;
        $response=$connect->post($this->host."/query",$this->data,$this->params);
        var_dump($response);
    }
}
